﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nwrole.plugin;
using nwrole.toolbox.sync.ServiceHost;

namespace nwrole.toolbox.sync.plugin
{
    public class SyncPlugin : nwrole.plugin.PluginBase
    {

        [NwroleConfig("SyncServiceEnabled")]
        public bool SyncServiceEnabled { get; set; }

        [NwroleConfig("TableSyncEnabled")]
        public bool TableSyncEnabled { get; set; }

        [NwroleConfig("SyncDestinationConStr")] // ADDED 120924 by Chanan
        public string SyncDestinationConStr { get; set; }

        protected SyncDestinationServiceHost serviceHost = null;

        protected override void OnStart()
        {
            // service host
            if (SyncServiceEnabled)
            {
                StartServiceHost();
            }

            // table sync
            if (TableSyncEnabled)
            {
                StartTableSync();
            }
        }

        private void StartTableSync()
        {
        }

        private void StartServiceHost()
        {
            try
            {
                serviceHost = new SyncDestinationServiceHost();
                //serviceHost.Open("net.msmq://./private/BackOfficeInbox", SyncDestinationConStr); // TODO: SyncServiceHost no longer creates an msmq endpoint. 120925
            }
            catch
            {
            }
        }


        protected override void OnStop()
        {
        }

        // mål kunna köra hela sync på nya servern i järfälla

        // todo 
        // starta en service host för inkommande anrop

        // todo
        // starta en tråd som kör sync med bestämda mellanrum

        // installera oracle client
        // installera oracle connection
        // installera nwrole 
        // installera plugin

    }
}
